﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiProject.Lib;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.DtoModel.SystemManager;

namespace SystemCenterSoa.ApiProject.Controllers
{
    [Route("api/SystemManager/[controller]/[action]")]
    [ApiController]
    [ServiceFilter(typeof(UserTokenVerificationAttribute))]//使用ServiceFilter会自动将依赖注入到过滤器中。因为过滤器的构造函数有注入的代码, 这里需要使用ServiceFilter 告诉他直接从di里获取注入
    public class MyBaseController : ControllerBase
    {

        public LoginUserDto LoginUserDto
        {
            get
            {
                return new LoginUserDto()
                {
                    user_name = "zzz",
                    user_full_name = "高楼画"
                };
                //return AdminUserBll.GetLoginUser();
            }
        }

        protected ResultModel<T> MyOk<T>(T data, string mess = "执行成功")
        {
            ResultModel<T> resultModel = new ResultModel<T>();
            resultModel.data = data;
            resultModel.code = ResultCode.Ok;
            resultModel.mess = mess;
            return resultModel;
        }

        protected ResultModel<T> MyError<T>(Exception ex, string mess = "出现错误")
        {
            ResultModel<T> resultModel = new ResultModel<T>();

            resultModel.code = ResultCode.Error;
            resultModel.mess = mess + "错误信息是:" + ex.ToString();
            return resultModel;
        }

        protected ResultModel<T> MyFail<T>(string mess = "出现错误")
        {
            ResultModel<T> resultModel = new ResultModel<T>();

            resultModel.code = ResultCode.Fail;
            resultModel.mess = mess;
            return resultModel;
        }
    }
}
